<!---
Copyright: (c) 2006 The MachBlog Authors
Authors: Matt Woodward (mpwoodward@gmail.com) & Peter J. Farrell (pjf@maestropublishing.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.

$Id: CheckLogin.cfc 1195 2007-07-18 05:05:59Z pfarrell $

Notes:
This event-filter is autowired by ColdSpring.
--->
<cfcomponent
	displayname="CheckLogin"
	extends="MachII.framework.EventFilter"
	output="false" 
	hint="CheckLogin filter for MachBlog">

	<!---
	PROPERTIES
	--->
	<cfproperty name="userFacade" type="org.machblog.facades.UserFacade" required="true" />
	
	<cfset variables.userFacade = "" />

	<!---
	INITIALIZATION / CONFIGURATION
	--->
	<cffunction name="configure" access="public" output="false" returntype="void"
		hint="Configures the event-filter.">
		<!--- Does nothing. --->
	</cffunction>

	<cffunction name="setUserFacade" access="public" output="false" returntype="void"
		hint="Dependency: injected">
		<cfargument name="userFacade" type="org.machblog.facades.UserFacade" required="true" />
		<cfset variables.userFacade = arguments.userFacade />
	</cffunction>	
	<cffunction name="getUserFacade" access="public" output="false" returntype="org.machblog.facades.UserFacade">
		<cfreturn variables.userFacade />
	</cffunction>
	
	<!---
	PUBLIC FUNCTIONS
	--->
	<cffunction name="filterEvent" access="public" output="false" returntype="boolean" 
		hint="Filters event and returns a boolean to Mach-II indicating whether or not the event queue 
		should proceed. If not, the event queue is cleared and a new event is announced.">
		<cfargument name="event" type="MachII.framework.Event" required="true" />
		<cfargument name="eventContext" type="MachII.framework.EventContext" required="true" />
		
		<cfset var proceed = false />
			
		<cfif getUserFacade().userExists()>
			<cfset proceed = true />
		<cfelse>
			<cfset arguments.event.setArg("message", "Either you are not logged in or your session has expired. Please log in.") />
			<cfset announceEvent("loginFailed", arguments.event.getArgs()) />
		</cfif>
		
		<cfreturn proceed />
	</cffunction>

</cfcomponent>